package Entry;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack {
    Queue<Integer> queue;
    int num=0;

    /** Initialize your data structure here. */
    public MyStack() {
        queue=new LinkedList<>();
    }

    /** Push element x onto stack. */
    public void push(int x) {
        queue.offer(x);
        num++;
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        int temp=num;
        Queue<Integer> q=new LinkedList<>();

        for (int i=0;i<num-1;i++){
            q.offer(queue.remove());
        }
        int res=queue.remove();
        queue=q;
        num--;
        return res;
    }

    /** Get the top element. */
    public int top() {
        int temp=num;
        Queue<Integer> q=new LinkedList<>();

        for (int i=0;i<num-1;i++){
            q.offer(queue.remove());
        }
        int res=queue.remove();
        q.offer(res);
        queue=q;
        return res;
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        if(num==0) return true;
        return false;
    }
}
